package top.shiyiri.spring5.testdemo;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import top.shiyiri.spring5.autowire.Emp;
import top.shiyiri.spring5.bean.Book;
import top.shiyiri.spring5.bean.Orders;
import top.shiyiri.spring5.bean.Stu;

/**
 * @author Aunean
 * @date 2022/2/16 21:39
 */
public class TestSpring5Demo1 {

    @Test
    public void test() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");

        Stu stu = context.getBean("stu", Stu.class);
        stu.test();
    }

    @Test
    public void test2() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean2.xml");

        Book book2 = context.getBean("book", Book.class);
        Book book1 = context.getBean("book", Book.class);
//        book.test();
        System.out.println(book2);
        System.out.println(book1);
    }

    @Test
    public void test3() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean3.xml");

        Book myBean = context.getBean("myBean", Book.class);
        System.out.println(myBean);
    }

    @Test
    public void test4() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean4.xml");

        Orders orders = context.getBean("orders", Orders.class);
        System.out.println("获取创建bean实例对象");

        System.out.println(orders);

        //手动让bean实例销毁
        context.close();
    }

    @Test
    public void test5() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean5.xml");

        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
    }
}
